package top.wkl.springboot3.controller;

import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.wkl.springboot3.base.R;
import top.wkl.springboot3.entity.TbFiles;
import top.wkl.springboot3.service.TbFilesService;

@RestController
@RequestMapping("/files")
@RequiredArgsConstructor
public class FilesController {

    private final TbFilesService tbFilesService;

    @PostMapping
    public R<TbFiles> upload(MultipartFile file) {
        return tbFilesService.upload(file);
    }

    @GetMapping("/{id}")
    public void download(@PathVariable Integer id, HttpServletResponse response) {
        tbFilesService.download(id, response);

    }
}
